<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <table border="1">
        <caption>用户列表</caption>
        <tr>
            <th>id</th>
            <th>用户名</th>
            <th>密码</th>
            <th>昵称</th>
            <th>年龄</th>
        </tr>
        <tr v-for="user in arr">
            <td>{{user.id}}</td>
            <!--:href  属性名前添加： 代表让属性的内容和变量进行绑定-->
            <td><a :href="'/update.html?id='+user.id">{{user.username}}</a></td>
            <td>{{user.password}}</td>
            <td>{{user.nick}}</td>
            <td>{{user.age}}</td>
        </tr>
    </table>
    <input type="button" value="请求数据" @click="fn()">
</div>
<!--引入axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!--引入vue框架-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    let v = new Vue({
        el: "div",
        data: {
            arr: [{id: 1, username: "lucy", password: "aabbcc", nick: "露西", age: 80},
                {id: 2, username: "lily", password: "123456", nick: "丽丽", age: 30},
                {id: 3, username: "lilei", password: "654321", nick: "李雷", age: 20}]
        },
        methods:{
            fn:function () {
            //    发出异步请求获取用户数据
                axios.get("/select").then(function (response) {
                //    把请求到的数据赋值给Vue里面的数据对象，页面会自动发生改变
                    v.arr=response.data;
                })
            }
        },
        created:function () { /*当vue对象被创建出来之后会立即执行的方法*/
            axios.get("/select").then(function (response) {
                v.arr=response.data;
            })
        }
    })
</script>


</body>
</html>